import sys
import subprocess
import os

def install_requirements():
    """安装网页应用所需的依赖"""
    requirements = [
        "fastapi",
        "uvicorn",
        "websockets",
        "jinja2",
        "python-multipart",
        "aiofiles"
    ]
    
    print("正在安装必要依赖...")
    for req in requirements:
        print(f"安装 {req}...")
        subprocess.check_call([sys.executable, "-m", "pip", "install", req])
    
    print("依赖安装完成！")

def create_directories():
    """创建必要的目录结构"""
    # 创建templates和static目录
    os.makedirs("templates", exist_ok=True)
    os.makedirs("static", exist_ok=True)
    
    print("目录结构已创建")

if __name__ == "__main__":
    install_requirements()
    create_directories()
    
    print("\n设置完成！")
    print("现在您可以运行 'python app.py' 来启动web应用")
    print("然后在浏览器中访问 http://localhost:8000")